import { isvalidUsername } from '@/utils/validate'
import { regPassword } from '@/utils/regular'
export default {
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!isvalidUsername(value)) {
        callback(new Error('请输入登录账号'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.trim() === '') {
        callback(new Error('请输入登录密码'))
      } else if (!regPassword(value, 'loginPassword')) {
        callback(new Error('登录密码格式不正确'))
      } else {
        callback()
      }
    }

    const validateCode = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('验证码格式不正确'))
      } else {
        callback()
      }
    }
    return {
      loginRules: {
        username: [
          {
            required: true,
            trigger: 'blur',
            validator: validateUsername
          }
        ],
        password: [
          {
            required: true,
            trigger: 'blur',
            validator: validatePassword
          }
        ],
        code: [
          {
            required: true,
            trigger: 'blur',
            validator: validateCode
          }
        ],
        agree: [
          {
            required: true,
            trigger: 'change',
            validator: validateCode
          }
        ]
      },
      passwordType: 'password'
    }
  }
}
